home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODUtil / Sources / FWFcsSet.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.4 KB  |  244 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFcsSet.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWFCSSET_H
  13. #include "FWFcsSet.h"
  14. #endif
  15.  
  16. // ----- OpenDoc Includes -----
  17.  
  18. #ifndef SOM_ODSession_xh
  19. #include <ODSessn.xh>
  20. #endif
  21.  
  22. #ifndef SOM_ODArbitrator_xh
  23. #include <Arbitrat.xh>
  24. #endif
  25.  
  26. #ifndef SOM_ODFocusSet_xh
  27. #include <FocusSet.xh>
  28. #endif
  29.  
  30. //========================================================================================
  31. //    Runtime Informations
  32. //========================================================================================
  33.  
  34. #if FW_LIB_EXPORT_PRAGMAS
  35. #pragma lib_export on
  36. #endif
  37.  
  38. #ifdef FW_BUILD_MAC    
  39. #pragma segment fwodutil
  40. #endif
  41.  
  42. //========================================================================================
  43. //    class FW_CFocusSet
  44. //========================================================================================
  45.  
  46. //----------------------------------------------------------------------------------------
  47. //    FW_CFocusSet::FW_CFocusSet
  48. //----------------------------------------------------------------------------------------
  49.  
  50. FW_CFocusSet::FW_CFocusSet(Environment* ev, ODSession* session) :
  51.     fFocusSetRep(NULL),
  52.     fSession(session)
  53. {
  54.     fFocusSetRep = new FW_CFocusSetRep(ev, session);
  55.  
  56.     FW_END_CONSTRUCTOR
  57. }
  58.  
  59. //----------------------------------------------------------------------------------------
  60. //    FW_CFocusSet::FW_CFocusSet
  61. //----------------------------------------------------------------------------------------
  62.  
  63. FW_CFocusSet::FW_CFocusSet(const FW_CFocusSet& other) :
  64.     fFocusSetRep(NULL),
  65.     fSession(other.fSession)
  66. {
  67.     other.fFocusSetRep->Acquire();
  68.     fFocusSetRep = other.fFocusSetRep;
  69.     fFociCount = other.fFociCount;
  70.     
  71.     FW_END_CONSTRUCTOR
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------
  75. //    FW_CFocusSet::~FW_CFocusSet
  76. //----------------------------------------------------------------------------------------
  77.  
  78. FW_CFocusSet::~FW_CFocusSet()
  79. {
  80.     FW_START_DESTRUCTOR
  81.  
  82.     fFocusSetRep->Release();
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. //    FW_CFocusSet::operator =
  87. //----------------------------------------------------------------------------------------
  88.  
  89. FW_CFocusSet& FW_CFocusSet::operator=(const FW_CFocusSet& other)
  90. {
  91.     if (fFocusSetRep != other.fFocusSetRep)
  92.     {
  93.         fFocusSetRep->Release();
  94.  
  95.         other.fFocusSetRep->Acquire();
  96.         fFocusSetRep = other.fFocusSetRep;
  97.         fFociCount = other.fFociCount;
  98.         FW_ASSERT(fSession == other.fSession);
  99.     }
  100.     
  101.     return *this;
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. //    FW_CFocusSet::CopyIfShared
  106. //----------------------------------------------------------------------------------------
  107.  
  108. void FW_CFocusSet::CopyIfShared(Environment* ev)
  109. {
  110.     if (fFocusSetRep->GetRefCount() > 1)
  111.     {
  112.         FW_CFocusSetRep* newFocusSetRep = new FW_CFocusSetRep(ev, fSession);
  113.     
  114.         FW_CFocusSetIterator ite(ev, *this);
  115.         for (ODTypeToken token = ite.First(ev); ite.IsNotComplete(ev); ite.Next(ev))
  116.         {
  117.             newFocusSetRep->fODFocusSet->Add(ev, token);
  118.         }
  119.  
  120.         fFocusSetRep->Release();
  121.         fFocusSetRep = newFocusSetRep;
  122.     }        
  123. }
  124.  
  125. //----------------------------------------------------------------------------------------
  126. //    FW_CFocusSet::Add
  127. //----------------------------------------------------------------------------------------
  128.  
  129. void FW_CFocusSet::Add(Environment* ev, ODTypeToken focus)
  130. {
  131.     if (!fFocusSetRep->fODFocusSet->Contains(ev, focus))
  132.     {
  133.         CopyIfShared(ev);
  134.         
  135.         fFociCount++;
  136.         fFocusSetRep->fODFocusSet->Add(ev, focus);
  137.     }
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CFocusSet::Remove
  142. //----------------------------------------------------------------------------------------
  143.  
  144. void FW_CFocusSet::Remove(Environment* ev, ODTypeToken focus)
  145. {
  146.     if (fFocusSetRep->fODFocusSet->Contains(ev, focus))
  147.     {
  148.         CopyIfShared(ev);
  149.  
  150.         fFociCount--;
  151.         fFocusSetRep->fODFocusSet->Remove(ev, focus);
  152.     }
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    FW_CFocusSet::Contains
  157. //----------------------------------------------------------------------------------------
  158.  
  159. FW_Boolean FW_CFocusSet::Contains(Environment* ev, ODTypeToken focus) const
  160. {
  161.     return fFocusSetRep->fODFocusSet->Contains(ev, focus);
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. //    FW_CFocusSet::RelinquishFocusSet
  166. //----------------------------------------------------------------------------------------
  167.  
  168. void FW_CFocusSet::RelinquishFocusSet(Environment* ev, ODFrame* frame) const
  169. {
  170.     fSession->GetArbitrator(ev)->RelinquishFocusSet(ev, fFocusSetRep->fODFocusSet, frame);
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. //    FW_CFocusSet::RequestFocusSet
  175. //----------------------------------------------------------------------------------------
  176.  
  177. FW_Boolean FW_CFocusSet::RequestFocusSet(Environment* ev, ODFrame* frame) const
  178. {
  179.     if (fFociCount != 0)
  180.         return fSession->GetArbitrator(ev)->RequestFocusSet(ev, fFocusSetRep->fODFocusSet, frame);
  181.     else
  182.         return FALSE;
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    FW_CFocusSet::CreateFocusSetIterator
  187. //----------------------------------------------------------------------------------------
  188.  
  189. ODFocusSetIterator* FW_CFocusSet::CreateFocusSetIterator(Environment* ev) const
  190. {
  191.     return fFocusSetRep->fODFocusSet->CreateIterator(ev);
  192. }
  193.  
  194. //========================================================================================
  195. //    class FW_CFocusSetRep
  196. //========================================================================================
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    FW_CFocusSetRep::FW_CFocusSetRep
  200. //----------------------------------------------------------------------------------------
  201.  
  202. FW_CFocusSetRep::FW_CFocusSetRep(Environment* ev, ODSession* session) :
  203.     fODFocusSet(NULL)
  204. {
  205.     fODFocusSet = session->GetArbitrator(ev)->CreateFocusSet(ev);
  206. }
  207.  
  208. //----------------------------------------------------------------------------------------
  209. //    FW_CFocusSetRep::~FW_CFocusSetRep
  210. //----------------------------------------------------------------------------------------
  211.  
  212. FW_CFocusSetRep::~FW_CFocusSetRep()
  213. {
  214.     delete fODFocusSet;
  215.     fODFocusSet = NULL;
  216. }
  217.  
  218. //========================================================================================
  219. //    class FW_CFocusSetIterator
  220. //========================================================================================
  221.  
  222. //----------------------------------------------------------------------------------------
  223. //    FW_CFocusSetIterator::FW_CFocusSetIterator
  224. //----------------------------------------------------------------------------------------
  225.  
  226. FW_CFocusSetIterator::FW_CFocusSetIterator(Environment* ev, const FW_CFocusSet& focusSet)
  227. {
  228.     fIterator = focusSet.CreateFocusSetIterator(ev);
  229.  
  230.     FW_END_CONSTRUCTOR
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    FW_CFocusSetIterator::~FW_CFocusSetIterator
  235. //----------------------------------------------------------------------------------------
  236.  
  237. FW_CFocusSetIterator::~FW_CFocusSetIterator()
  238. {
  239.     FW_START_DESTRUCTOR
  240.     
  241.     delete fIterator;
  242.     fIterator = NULL;
  243. }
  244.